<?php


namespace app\zyhsapi\model;


use app\common\model\BaseCache;
use XznsTools\cache\CacheManage;

class ZyhsLoginLog extends BaseCacheZyhs
{
    protected $table = 'good_wechat.zyhs_login_log';
    protected $cacheModel = 'user.login_log';

    public function SaveData($map)
    {
        try
        {
            $this->save($map);
        }
        catch (\Exception $e)
        {
            return false;
        }
        return true;
    }


    public function getUserLogFromCache($uid)
    {
        return CacheManage::getInstance()->setCacheConfig($this->cacheModel, $uid)->getDataAndSet(function () use ($uid)
        {
            return $this->getUserLogFromDb($uid);
        });
    }

    public function getUserLogFromDb($uid)
    {
        try
        {
            $data = $this->field('id,uid,login_type,login_time,login_ip')->where(['uid' => $uid])->findOrFail()->toArray();
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }
}